home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 124 / cd-rom 124.iso / edu / tuxmath / tuxmathscrabble / asymptopia / tuxmathscrabble.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2003-11-16  |  23.7 KB  |  757 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.2)
  3.  
  4. '''
  5. /***************************************************************************
  6.  
  7. \tAuthor \t\t\t:Charles B. Cosse 
  8. \t
  9. \tEmail\t\t\t:ccosse@asymptopia.com
  10. \t\t\t\t\t
  11. \t\t\t\t\t
  12. \tCopyright\t\t:(C) 2002,2003 Asymptopia Software.
  13. \t
  14.  ***************************************************************************/
  15. /***************************************************************************
  16.                           tuxmathscrabble.py
  17.  
  18.  ***************************************************************************/
  19.  
  20. /***************************************************************************
  21.  *                                                                         *
  22.  *   This program is free software; you can redistribute it and/or modify  *
  23.  *   it under the terms of the GNU General Public License as published by  *
  24.  *   the Free Software Foundation; either version 2 of the License, or     *
  25.  *   (at your option) any later version. (Please note that if you use this *
  26.  *   code you must give credit by including the Author and Copyright       *
  27.  *   info at the top of this file).                                        *
  28.  ***************************************************************************/
  29. '''
  30. import os
  31. import pygame
  32. import sys
  33. from pygame.locals import *
  34. from random import random
  35. from asymptopia.myutil import load_image
  36. from asymptopia.Board import *
  37. from asymptopia.Spot import *
  38. from asymptopia.myutil import *
  39. from asymptopia.Tile import *
  40. from asymptopia.Button import *
  41. from asymptopia.Validator import *
  42. from asymptopia.Localizer import *
  43. from asymptopia.Tux import *
  44. from asymptopia.Animator import *
  45. from asymptopia.AnimatedChar import *
  46. from asymptopia.CuckooManeuvers import CuckooManeuvers
  47. from asymptopia.TuxManeuvers import TuxManeuvers
  48.  
  49. try:
  50.     for sitepkgdir in sys.path:
  51.         if sitepkgdir[-13:] == 'site-packages':
  52.             break
  53.         
  54. except:
  55.     pass
  56.  
  57. if not (pygame.font):
  58.     print 'Warning, fonts disabled'
  59.  
  60. if not (pygame.mixer):
  61.     print 'Warning, sound disabled'
  62.  
  63. M = 13
  64. N = 17
  65. W = 800
  66. H = 600
  67. DEFAULT_LEVEL = 5
  68. WAIT_TIME = 100
  69.  
  70. class TuxMathScrabble:
  71.     
  72.     def __init__(self, level):
  73.         pygame.init()
  74.         screen = pygame.display.set_mode((W, H))
  75.         pygame.display.set_caption('www.asymptopia.com')
  76.         pygame.mouse.set_visible(1)
  77.         self.pyfont = pygame.font.Font(os.path.join(sitepkgdir, 'asymptopia/font/freesansbold.ttf'), 16)
  78.         self.LEVEL = level
  79.         self.tux_wait_counter = 0
  80.         slide1 = load_sound('asymptopia/sounds/slide01.wav')
  81.         slide2 = load_sound('asymptopia/sounds/slide02.wav')
  82.         boink = load_sound('asymptopia/sounds/bong05.wav')
  83.         kerplunk = load_sound('asymptopia/sounds/beep07.wav')
  84.         win_sound_01 = load_sound('asymptopia/sounds/sparcle.wav')
  85.         win_sound_02 = load_sound('asymptopia/sounds/bullcall.wav')
  86.         win_sound_03 = load_sound('asymptopia/sounds/aooga.wav')
  87.         lose_sound = load_sound('asymptopia/sounds/foghorn2.wav')
  88.         pop01 = load_sound('asymptopia/sounds/pop01.wav')
  89.         pop02 = load_sound('asymptopia/sounds/pop01.wav')
  90.         animator = Animator()
  91.         self.tuxManeuvers = TuxManeuvers()
  92.         AnimatedTux = AnimatedChar(self.tuxManeuvers.getSequencesPyld(), W / 2, 100)
  93.         animator.add_char('Tux', AnimatedTux)
  94.         tuxManeuversPyld = self.tuxManeuvers.getManeuversPyld()
  95.         for key in tuxManeuversPyld:
  96.             animator.define_maneuver(key, tuxManeuversPyld[key])
  97.         
  98.         self.cuckooManeuvers = CuckooManeuvers()
  99.         AnimatedTiles = []
  100.         AnimatedTileNames = []
  101.         for idx in range(N):
  102.             AnimatedTiles.append(AnimatedChar(self.cuckooManeuvers.getSequencesPyld(), -25, -25))
  103.             new_name = 'Tile_%02d' % idx
  104.             AnimatedTileNames.append(new_name)
  105.             animator.add_char(AnimatedTileNames[idx], AnimatedTiles[idx])
  106.         
  107.         cuckooManeuversPyld = self.cuckooManeuvers.getManeuversPyld()
  108.         for key in cuckooManeuversPyld:
  109.             animator.define_maneuver(key, cuckooManeuversPyld[key])
  110.         
  111.         help_button = Button('asymptopia/images/help.gif')
  112.         help_button.rect.center = (W - 70, H - 285)
  113.         credit_button = Button('asymptopia/images/credits.gif')
  114.         credit_button.rect.center = (W - 70, H - 235)
  115.         skip_button = Button('asymptopia/images/skip.gif')
  116.         skip_button.rect.center = (W - 70, H - 135)
  117.         ready_button = Button('asymptopia/images/ready.gif')
  118.         ready_button.rect.center = (W - 70, H - 185)
  119.         l1_button = Button('asymptopia/images/level_one.gif')
  120.         l1_button.rect.center = (65, H - 135)
  121.         l2_button = Button('asymptopia/images/level_two.gif')
  122.         l2_button.rect.center = (65, H - 185)
  123.         l3_button = Button('asymptopia/images/level_three.gif')
  124.         l3_button.rect.center = (65, H - 235)
  125.         l4_button = Button('asymptopia/images/level_four.gif')
  126.         l4_button.rect.center = (65, H - 285)
  127.         buttongroup = pygame.sprite.Group([
  128.             help_button,
  129.             ready_button,
  130.             skip_button,
  131.             credit_button,
  132.             l1_button,
  133.             l2_button,
  134.             l3_button,
  135.             l4_button])
  136.         buttons = pygame.sprite.RenderPlain(buttongroup)
  137.         background = pygame.Surface(screen.get_size())
  138.         background = background.convert()
  139.         background.fill((0, 150, 100))
  140.         level_indicator = pygame.Surface((10, 10))
  141.         level_indicator = level_indicator.convert()
  142.         level_indicator.fill((255, 0, 0))
  143.         board = Board(M, N, W / 2, H / 2, None, 'asymptopia/images/new_spot.gif')
  144.         boardspots = pygame.sprite.RenderPlain(board.get_spots())
  145.         if self.LEVEL == 3 or self.LEVEL == 4:
  146.             NTRAYSPOTS = 12
  147.             NNUMBERS = 7
  148.         else:
  149.             NTRAYSPOTS = 10
  150.             NNUMBERS = 6
  151.         tray = Board(1, NTRAYSPOTS, W / 2, H - 40, None, 'asymptopia/images/new_spot.gif')
  152.         trayspots = pygame.sprite.RenderPlain(tray.get_spots())
  153.         submission = Board(M, N, W / 2, H / 2, None, 'asymptopia/images/new_spot.gif')
  154.         submissionspots = pygame.sprite.RenderPlain()
  155.         target = pygame.sprite.RenderClear()
  156.         validator = Validator(board, self)
  157.         localizer = Localizer(board, self)
  158.         self.NTRAYSPOTS = NTRAYSPOTS
  159.         self.NNUMBERS = NNUMBERS
  160.         self.localizer = localizer
  161.         self.validator = validator
  162.         self.screen = screen
  163.         self.boink = boink
  164.         self.kerplunk = kerplunk
  165.         self.slide1 = slide1
  166.         self.slide2 = slide2
  167.         self.win_sound_01 = win_sound_01
  168.         self.win_sound_02 = win_sound_02
  169.         self.win_sound_03 = win_sound_03
  170.         self.lose_sound = lose_sound
  171.         self.submissionspots = submissionspots
  172.         self.submission = submission
  173.         self.board = board
  174.         self.boardspots = boardspots
  175.         self.tray = tray
  176.         self.trayspots = trayspots
  177.         self.target = target
  178.         self.background = background
  179.         self.level_indicator = level_indicator
  180.         self.buttons = buttons
  181.         self.help_button = help_button
  182.         self.ready_button = ready_button
  183.         self.skip_button = skip_button
  184.         self.credit_button = credit_button
  185.         self.l1_button = l1_button
  186.         self.l2_button = l2_button
  187.         self.l3_button = l3_button
  188.         self.l4_button = l4_button
  189.         self.animator = animator
  190.         self.AnimatedTux = AnimatedTux
  191.         self.AnimatedTiles = AnimatedTiles
  192.         self.AnimatedTileNames = AnimatedTileNames
  193.         self.num_animated_tiles = 0
  194.         self.animation_in_progress = 0
  195.         self.tuxturn = 0
  196.         tuxtray = Board(1, NTRAYSPOTS, W / 2, 70, None, 'asymptopia/images/new_spot.gif')
  197.         tuxtrayspots = pygame.sprite.RenderPlain(tuxtray.get_spots())
  198.         self.tuxtrayspots = tuxtrayspots
  199.         self.tuxtray = tuxtray
  200.         tux = Tux(self)
  201.         self.tux = tux
  202.  
  203.     
  204.     def draw_tiles(self, spots, who):
  205.         imgnames = [
  206.             'zero',
  207.             'one',
  208.             'two',
  209.             'three',
  210.             'four',
  211.             'five',
  212.             'six',
  213.             'seven',
  214.             'eight',
  215.             'nine',
  216.             'ten',
  217.             'eleven',
  218.             'twelve',
  219.             'thirteen',
  220.             'fourteen',
  221.             'fifteen',
  222.             'twenty']
  223.         for spot in spots:
  224.             if spot.occupied():
  225.                 continue
  226.             
  227.             if spot.getMN()[1] < self.NNUMBERS:
  228.                 if self.LEVEL == 4:
  229.                     int_val = int(16 * random()) + 1
  230.                 elif self.LEVEL == 3:
  231.                     int_val = int(10 * random()) + 1
  232.                 elif self.LEVEL == 2:
  233.                     int_val = int(15 * random())
  234.                 else:
  235.                     int_val = int(10 * random())
  236.                 str_val = `int_val` + '.0'
  237.                 if int_val == 16:
  238.                     str_val = '20.0'
  239.                 
  240.                 if who == 'tux':
  241.                     fname = 'asymptopia/images/tux_' + imgnames[int_val] + '.gif'
  242.                 else:
  243.                     fname = 'asymptopia/images/' + imgnames[int_val] + '.gif'
  244.             elif spot.getMN()[1] < self.NTRAYSPOTS - 1:
  245.                 opnames = [
  246.                     'new_plus',
  247.                     'new_minus',
  248.                     'new_mult',
  249.                     'new_divide']
  250.                 if self.LEVEL == 4:
  251.                     idx = int(4 * random())
  252.                 elif self.LEVEL == 3:
  253.                     idx = int(3 * random())
  254.                 else:
  255.                     idx = int(2 * random())
  256.                 int_val = None
  257.                 if opnames[idx] == 'new_plus':
  258.                     str_val = '+'
  259.                 elif opnames[idx] == 'new_minus':
  260.                     str_val = '-'
  261.                 elif opnames[idx] == 'new_mult':
  262.                     str_val = '*'
  263.                 elif opnames[idx] == 'new_divide':
  264.                     str_val = '/'
  265.                 
  266.                 if who == 'tux':
  267.                     opnames[idx] = 'tux_' + opnames[idx]
  268.                 
  269.                 fname = 'asymptopia/images/' + opnames[idx] + '.gif'
  270.             elif who == 'tux':
  271.                 fname = 'asymptopia/images/tux_new_equal.gif'
  272.             else:
  273.                 fname = 'asymptopia/images/new_equal.gif'
  274.             int_val = None
  275.             str_val = '='
  276.             tile = Tile(fname, int_val, str_val)
  277.             spot.take_guest(tile, 1)
  278.             tile.saved_center = spot.rect.center
  279.         
  280.  
  281.     
  282.     def play(self):
  283.         AnimatedTiles = self.AnimatedTiles
  284.         AnimatedTileNames = self.AnimatedTileNames
  285.         AnimatedTux = self.AnimatedTux
  286.         animator = self.animator
  287.         tux = self.tux
  288.         validator = self.validator
  289.         localizer = self.localizer
  290.         screen = self.screen
  291.         boink = self.boink
  292.         kerplunk = self.kerplunk
  293.         slide1 = self.slide1
  294.         slide2 = self.slide2
  295.         win_sound_01 = self.win_sound_01
  296.         win_sound_02 = self.win_sound_02
  297.         win_sound_03 = self.win_sound_03
  298.         lose_sound = self.lose_sound
  299.         submissionspots = self.submissionspots
  300.         submission = self.submission
  301.         board = self.board
  302.         boardspots = self.boardspots
  303.         tray = self.tray
  304.         trayspots = self.trayspots
  305.         target = self.target
  306.         background = self.background
  307.         level_indicator = self.level_indicator
  308.         buttons = self.buttons
  309.         help_button = self.help_button
  310.         ready_button = self.ready_button
  311.         skip_button = self.skip_button
  312.         credit_button = self.credit_button
  313.         l1_button = self.l1_button
  314.         l2_button = self.l2_button
  315.         l3_button = self.l3_button
  316.         l4_button = self.l4_button
  317.         tuxtrayspots = self.tuxtrayspots
  318.         tuxtray = self.tuxtray
  319.         self.draw_tiles(tray.get_spots(), 'player')
  320.         self.draw_tiles(tuxtray.get_spots(), 'tux')
  321.         tuxturn = self.tuxturn
  322.         num_animated_tiles = self.num_animated_tiles
  323.         animation_in_progress = self.animation_in_progress
  324.         self.tuxscore = 0
  325.         self.playerscore = 0
  326.         coin = 0
  327.         if coin == 0:
  328.             animator.start_maneuver('Tux', 'tux_welcome_maneuver_01')
  329.         
  330.         animation_in_progress = 1
  331.         tux_move_progress = 0
  332.         tile_animation_in_progress = 0
  333.         num_animated_tiles = 0
  334.         while 1:
  335.             num_animated_tiles = self.num_animated_tiles
  336.             animation_in_progress = self.animation_in_progress
  337.             if tuxturn == 1 and tux_move_progress == 0 and animation_in_progress == 0 and num_animated_tiles == 0:
  338.                 coin = int(random() * 4)
  339.                 if coin == 0:
  340.                     animator.start_maneuver('Tux', 'tux_get_up_maneuver_01')
  341.                 elif coin == 1:
  342.                     animator.start_maneuver('Tux', 'tux_get_up_maneuver_02')
  343.                 elif coin == 2:
  344.                     animator.start_maneuver('Tux', 'tux_get_up_maneuver_03')
  345.                 else:
  346.                     animator.start_maneuver('Tux', 'tux_get_up_maneuver_04')
  347.                 tux_move_progress = 1
  348.                 animation_in_progress = 1
  349.             
  350.             if num_animated_tiles == 0 and animation_in_progress == 0 and tuxturn == 1:
  351.                 tux.generate_expressions()
  352.                 tux_finished = 0
  353.                 while tux_finished != 1:
  354.                     tux_submission = tux.generate_options()
  355.                     rlist = tux_submission
  356.                     if tux_submission == None:
  357.                         tux_finished = 1
  358.                         tuxturn = 0
  359.                         self.tux_wait_counter = 0
  360.                         animator.start_maneuver('Tux', 'return_stumped_maneuver')
  361.                         break
  362.                     
  363.                     if rlist == None:
  364.                         pass
  365.                     elif rlist[0][0] == rlist[1][0]:
  366.                         exprtype = 'row'
  367.                     else:
  368.                         exprtype = 'col'
  369.                     
  370.                     try:
  371.                         for idx in range(len(rlist)):
  372.                             tile = tuxtray.get_guest_by_str(rlist[idx][0])
  373.                             spot = submission.take_guestMN(tile, rlist[idx][1], rlist[idx][2])
  374.                             submissionspots.add(spot)
  375.                     except:
  376.                         raw_input()
  377.  
  378.                     board.increment_num_commited()
  379.                     for spot in submissionspots.sprites():
  380.                         for board_spot in board.get_spots():
  381.                             if board_spot.rect.center == spot.rect.center:
  382.                                 tile = spot.pop_guest()
  383.                                 board_spot.take_guest(tile, 1)
  384.                                 board_spot.lock()
  385.                                 submission.remove(spot)
  386.                             
  387.                         
  388.                     
  389.                     submissionspots.empty()
  390.                     self.draw_tiles(tuxtray.get_spots(), 'tux')
  391.                     tux_finished = 1
  392.                     tuxturn = 0
  393.                     coin = int(random() * 3)
  394.                     if coin == 0:
  395.                         animator.start_maneuver('Tux', 'return_skating_maneuver')
  396.                     elif coin == 1:
  397.                         animator.start_maneuver('Tux', 'tux_go_back_from_tray_maneuver_01')
  398.                     else:
  399.                         animator.start_maneuver('Tux', 'tux_go_back_from_tray_maneuver_02')
  400.             
  401.             for event in pygame.event.get():
  402.                 if event.type == QUIT:
  403.                     return 0
  404.                 elif event.type == KEYDOWN and event.key == K_ESCAPE:
  405.                     return 0
  406.                 elif event.type == KEYDOWN and event.key == K_F1:
  407.                     display_surface = pygame.display.get_surface()
  408.                     pygame.image.save(display_surface, os.path.join(os.environ['HOME'], 'tuxmathscrabble.bmp'))
  409.                 elif event.type == MOUSEBUTTONDOWN:
  410.                     self.tux_wait_counter = 0
  411.                     if help_button.rect.collidepoint(pygame.mouse.get_pos()):
  412.                         (help_image, rect) = load_image('asymptopia/images/help_splash.gif')
  413.                         self.screen.blit(help_image, (0, 0))
  414.                         pygame.display.flip()
  415.                         while 1:
  416.                             breakout = 0
  417.                             for event in pygame.event.get():
  418.                                 if event.type == KEYDOWN:
  419.                                     breakout = 1
  420.                                 elif event.type == MOUSEBUTTONDOWN:
  421.                                     breakout = 1
  422.                                 
  423.                             
  424.                             if breakout:
  425.                                 break
  426.                             
  427.                     
  428.                     if credit_button.rect.collidepoint(pygame.mouse.get_pos()):
  429.                         (credit_image, rect) = load_image('asymptopia/images/credit_splash.gif')
  430.                         self.screen.blit(credit_image, (0, 0))
  431.                         pygame.display.flip()
  432.                         while 1:
  433.                             breakout = 0
  434.                             for event in pygame.event.get():
  435.                                 if event.type == KEYDOWN:
  436.                                     breakout = 1
  437.                                 elif event.type == MOUSEBUTTONDOWN:
  438.                                     breakout = 1
  439.                                 
  440.                             
  441.                             if breakout:
  442.                                 break
  443.                             
  444.                     
  445.                     if l1_button.rect.collidepoint(pygame.mouse.get_pos()):
  446.                         self.LEVEL = 1
  447.                         return 1
  448.                     
  449.                     if l2_button.rect.collidepoint(pygame.mouse.get_pos()):
  450.                         self.LEVEL = 2
  451.                         return 2
  452.                     
  453.                     if l3_button.rect.collidepoint(pygame.mouse.get_pos()):
  454.                         self.LEVEL = 3
  455.                         return 3
  456.                     
  457.                     if l4_button.rect.collidepoint(pygame.mouse.get_pos()):
  458.                         self.LEVEL = 4
  459.                         return 4
  460.                     elif skip_button.rect.collidepoint(pygame.mouse.get_pos()):
  461.                         if tuxturn == 1 or AnimatedTux.rect[0] < 400:
  462.                             continue
  463.                         else:
  464.                             for spot in submissionspots.sprites():
  465.                                 tile = spot.pop_guest()
  466.                                 if tile:
  467.                                     for spot in tray.get_spots():
  468.                                         if tile.saved_center == spot.rect.center:
  469.                                             spot.take_guest(tile, 1)
  470.                                         
  471.                                     
  472.                                 
  473.                             
  474.                             if len(board.get_listofheads()) == 0:
  475.                                 if not animation_in_progress:
  476.                                     animator.start_maneuver('Tux', 'insist_yougofirst_maneuver')
  477.                                 
  478.                             else:
  479.                                 animator.start_maneuver('Tux', 'head_tilt_right_maneuver')
  480.                                 lose_sound.play()
  481.                                 animation_in_progress = 1
  482.                                 tux_move_progress = 0
  483.                                 submissionspots.empty()
  484.                                 tuxturn = 1
  485.                     elif ready_button.rect.collidepoint(pygame.mouse.get_pos()):
  486.                         if validator.validate(submissionspots.sprites()):
  487.                             board.increment_num_commited()
  488.                             for spot in submissionspots.sprites():
  489.                                 for board_spot in board.get_spots():
  490.                                     if board_spot.rect.center == spot.rect.center and spot.guest:
  491.                                         tile = spot.pop_guest()
  492.                                         rect = board_spot.rect
  493.                                         xc = rect[0] + rect[2] / 2
  494.                                         yc = rect[1] + rect[3] / 2
  495.                                         cuckoo_tile_center = (xc, yc)
  496.                                         AnimatedTiles[num_animated_tiles].set_center(cuckoo_tile_center)
  497.                                         if spot.AMHEAD == 1:
  498.                                             board_spot.AMHEAD = 1
  499.                                             if spot.AMROWEXPR == 1:
  500.                                                 board_spot.AMROWEXPR = 1
  501.                                                 board_spot.ROWEXPRLENGTH = spot.ROWEXPRLENGTH
  502.                                             
  503.                                             if spot.AMCOLEXPR == 1:
  504.                                                 board_spot.AMCOLEXPR = 1
  505.                                                 board_spot.COLEXPRLENGTH = spot.COLEXPRLENGTH
  506.                                             
  507.                                         
  508.                                         board_spot.take_guest(tile, 1)
  509.                                         board_spot.lock()
  510.                                         submission.remove(spot)
  511.                                     
  512.                                 
  513.                                 num_animated_tiles = num_animated_tiles + 1
  514.                             
  515.                             coin = int(random() * 2)
  516.                             if coin == 0:
  517.                                 win_sound_01.play()
  518.                             else:
  519.                                 win_sound_02.play()
  520.                             coin = int(random() * 2)
  521.                             if coin == 0:
  522.                                 animator.start_maneuver('Tux', 'forehead_slap_maneuver')
  523.                             else:
  524.                                 animator.start_maneuver('Tux', 'neck_stretch_maneuver')
  525.                             tux_move_progress = 0
  526.                             animation_in_progress = 1
  527.                             cuckoo_maneuver_names = self.cuckooManeuvers.getManeuverNames()
  528.                             for idx in range(num_animated_tiles):
  529.                                 maneuver_idx = int(random() * len(cuckoo_maneuver_names))
  530.                                 animator.start_maneuver(AnimatedTileNames[idx], cuckoo_maneuver_names[maneuver_idx])
  531.                             
  532.                             self.num_animated_tiles = num_animated_tiles
  533.                             self.draw_tiles(tray.get_spots(), 'player')
  534.                             tuxturn = 1
  535.                         else:
  536.                             for spot in submissionspots.sprites():
  537.                                 tile = spot.pop_guest()
  538.                                 if tile:
  539.                                     for spot in tray.get_spots():
  540.                                         if tile.saved_center == spot.rect.center:
  541.                                             spot.take_guest(tile, 1)
  542.                                         
  543.                                     
  544.                                 
  545.                             
  546.                             if len(self.board.get_listofheads()) > 0:
  547.                                 lose_sound.play()
  548.                                 animator.start_maneuver('Tux', 'head_tilt_left_maneuver')
  549.                                 tux_move_progress = 0
  550.                                 animation_in_progress = 1
  551.                             
  552.                         submissionspots.empty()
  553.                         continue
  554.                     
  555.                     for spot in tray.get_spots():
  556.                         if not (spot.guest):
  557.                             continue
  558.                         
  559.                         if spot.rect.collidepoint(pygame.mouse.get_pos()):
  560.                             slide1.play()
  561.                             target.add(spot.pop_guest())
  562.                         
  563.                     
  564.                     for spot in board.get_spots():
  565.                         if spot.rect.collidepoint(pygame.mouse.get_pos()) and spot.islocked():
  566.                             boink.play()
  567.                         
  568.                     
  569.                     for spot in submission.get_spots():
  570.                         if not spot.occupied():
  571.                             continue
  572.                         
  573.                         if spot.rect.collidepoint(pygame.mouse.get_pos()):
  574.                             guest = spot.pop_guest()
  575.                             submissionspots.remove(spot)
  576.                             slide1.play()
  577.                             target.add(guest)
  578.                         
  579.                     
  580.                 elif event.type == MOUSEBUTTONUP:
  581.                     if len(target.sprites()) > 0:
  582.                         for spot in submission.get_spots():
  583.                             if spot.rect.collidepoint(target.sprites()[0].rect.center):
  584.                                 if spot.occupied():
  585.                                     continue
  586.                                 
  587.                                 spot.take_guest(target.sprites()[0], 1)
  588.                                 kerplunk.play()
  589.                                 submissionspots.add(spot)
  590.                                 target.empty()
  591.                                 break
  592.                             
  593.                         
  594.                         if len(target.sprites()) == 0:
  595.                             continue
  596.                         
  597.                         for spot in board.get_spots():
  598.                             if spot.rect.collidepoint(target.sprites()[0].rect.center):
  599.                                 boink.play()
  600.                                 break
  601.                             
  602.                         
  603.                         if len(target.sprites()) > 0:
  604.                             tile = target.sprites()[0]
  605.                             target.remove(tile)
  606.                             for spot in tray.get_spots():
  607.                                 if tile.saved_center == spot.rect.center:
  608.                                     spot.take_guest(tile, 1)
  609.                                     break
  610.                                 
  611.                             
  612.                         
  613.                     
  614.                 
  615.             
  616.             if not tuxturn:
  617.                 self.tux_wait_counter = self.tux_wait_counter + 1
  618.                 if self.tux_wait_counter > WAIT_TIME and self.animation_in_progress == 0:
  619.                     self.tux_wait_maneuver()
  620.                 else:
  621.                     tux_wait_counter = 0
  622.             
  623.             self.update()
  624.             self.tuxturn = tuxturn
  625.  
  626.     
  627.     def do_one_scratch(self):
  628.         coin = int(random() * 2)
  629.         if coin == 0:
  630.             self.animator.start_maneuver('Tux', 'one_scratchl_maneuver')
  631.         else:
  632.             self.animator.start_maneuver('Tux', 'one_scratchr_maneuver')
  633.         self.tux_move_progress = 0
  634.         self.update()
  635.         self.update()
  636.         self.update()
  637.         self.update()
  638.  
  639.     
  640.     def tux_wait_maneuver(self):
  641.         idx = int(random() * 9)
  642.         if idx == 0:
  643.             self.animator.start_maneuver('Tux', 'head_tilt_left_maneuver')
  644.         
  645.         if idx == 1:
  646.             self.animator.start_maneuver('Tux', 'head_tilt_right_maneuver')
  647.         
  648.         if idx == 2:
  649.             self.animator.start_maneuver('Tux', 'neck_stretch_maneuver')
  650.         
  651.         if idx == 3:
  652.             self.animator.start_maneuver('Tux', 'tux_flapper_maneuver')
  653.         
  654.         if idx == 5:
  655.             self.animator.start_maneuver('Tux', 'hop_in_place_maneuver')
  656.         
  657.         if idx == 6:
  658.             self.animator.start_maneuver('Tux', 'walkoff_stage_right_maneuver')
  659.         
  660.         if idx == 7:
  661.             self.animator.start_maneuver('Tux', 'neck_squash_tiltleftright_maneuver')
  662.         
  663.         if idx == 8:
  664.             self.animator.start_maneuver('Tux', 'neck_squash_hop_in_place_maneuver')
  665.         
  666.         self.tux_move_progress = 0
  667.         self.tux_wait_counter = 0
  668.         self.update()
  669.  
  670.     
  671.     def update(self):
  672.         screen = self.screen
  673.         background = self.background
  674.         buttons = self.buttons
  675.         boardspots = self.boardspots
  676.         trayspots = self.trayspots
  677.         submissionspots = self.submissionspots
  678.         target = self.target
  679.         AnimatedTux = self.AnimatedTux
  680.         animation_in_progress = self.animation_in_progress
  681.         AnimatedTiles = self.AnimatedTiles
  682.         tuxtrayspots = self.tuxtrayspots
  683.         for event in pygame.event.get():
  684.             if event.type == QUIT:
  685.                 return 0
  686.             elif event.type == KEYDOWN and event.key == K_ESCAPE:
  687.                 return 0
  688.             
  689.         
  690.         screen.blit(background, (0, 0))
  691.         if self.LEVEL == 1:
  692.             b = self.l1_button
  693.         elif self.LEVEL == 2:
  694.             b = self.l2_button
  695.         elif self.LEVEL == 3:
  696.             b = self.l3_button
  697.         elif self.LEVEL == 4:
  698.             b = self.l4_button
  699.         
  700.         screen.blit(self.level_indicator, (10, b.rect[1] + b.rect[3] / 3))
  701.         tuxscorestring = " Tux's Score: %03d" % self.tuxscore
  702.         screen.blit(self.pyfont.render(tuxscorestring, 1, (255, 255, 0, 0), (0, 150, 100)), (20, 30))
  703.         playerscorestring = ' Your Score : %03d' % self.playerscore
  704.         screen.blit(self.pyfont.render(playerscorestring, 1, (255, 255, 0, 0), (0, 150, 100)), (20, 60))
  705.         if self.LEVEL == 3:
  706.             if self.tuxturn == 1:
  707.                 tuxturnstring = "<-- Tux's Turn"
  708.                 screen.blit(self.pyfont.render(tuxturnstring, 1, (255, 255, 0, 0), (0, 150, 100)), (W - 180, 45))
  709.             else:
  710.                 yourturnstring = '<-- Your Turn!'
  711.                 screen.blit(self.pyfont.render(yourturnstring, 1, (255, 255, 0, 0), (0, 150, 100)), (W - 180, 530))
  712.         elif self.tuxturn == 1:
  713.             tuxturnstring = "<-- Tux's Turn"
  714.             screen.blit(self.pyfont.render(tuxturnstring, 1, (255, 255, 0, 0), (0, 150, 100)), (W - 200, 45))
  715.         else:
  716.             yourturnstring = '<-- Your Turn!'
  717.             screen.blit(self.pyfont.render(yourturnstring, 1, (255, 255, 0, 0), (0, 150, 100)), (W - 200, 530))
  718.         buttons.draw(screen)
  719.         boardspots.draw(screen)
  720.         submissionspots.draw(screen)
  721.         trayspots.draw(screen)
  722.         tuxtrayspots.draw(screen)
  723.         if len(target.sprites()) > 0:
  724.             target.sprites()[0].update()
  725.             target.draw(screen)
  726.         
  727.         rval = AnimatedTux.update()
  728.         screen.blit(AnimatedTux.image, (AnimatedTux.rect[0], AnimatedTux.rect[1]))
  729.         sound = AnimatedTux.get_sound()
  730.         if sound:
  731.             sound.play()
  732.         
  733.         if AnimatedTux.get_dest():
  734.             self.animation_in_progress = 1
  735.         else:
  736.             self.animation_in_progress = 0
  737.         if self.num_animated_tiles > 0:
  738.             self.num_animated_tiles = 0
  739.             for tile in AnimatedTiles:
  740.                 if not tile.get_dest():
  741.                     tile.set_center((0, 0))
  742.                 else:
  743.                     self.num_animated_tiles = self.num_animated_tiles + 1
  744.                     rval = tile.update()
  745.                     screen.blit(tile.image, (tile.rect[0], tile.rect[1]))
  746.             
  747.         
  748.         pygame.display.flip()
  749.         if AnimatedTux.get_dest():
  750.             if AnimatedTux.rect[0] < 0:
  751.                 AnimatedTux.set_center((730, 100))
  752.             
  753.             time.sleep(AnimatedTux.get_timeout())
  754.         
  755.  
  756.  
  757.